module CustCrypt

	require 'openssl'
	require 'digest/sha1'

	def self.encrypt(s, k)
		c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
		c.encrypt
		c.key = c.iv = Digest::SHA1.hexdigest(k)
		ret = c.update(s)
		ret << c.final

		Base64.encode64(ret)
	end

	def self.decrypt(s, k)
		s = Base64.decode64(s)

		c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
		c.decrypt
		c.key = c.iv = Digest::SHA1.hexdigest(k)
		ret = c.update(s)
		ret << c.final

		return ret
	end
end
